package edu.rit.cs.ws;

import java.util.ArrayList;
import java.util.List;

import javax.jws.WebService;

import org.springframework.beans.factory.annotation.Autowired;

import edu.rit.cs.core.pojos.Symbol;
import edu.rit.cs.core.services.daos.SymbolDAO;
import edu.rit.cs.ws.infos.SymbolInfo;

/**
 * The actual implementation of the web service being published.
 * 
 * @author Abhishek Shrestha (axs1430)
 * @author Juan Saldana (jjs6109)
 * @author Victor Alvarez (vxa1557)
 */
@WebService(endpointInterface = "edu.rit.cs.ws.MarketService")
public class MarketServiceImpl implements MarketService {

  @Autowired
  private SymbolDAO sd;

  /**
   * @param sd the SymbolService to set
   */
  public void setSd(SymbolDAO sd) {
    this.sd = sd;
  }

  /**
   * @return A hello string.
   */
  public String sayHi(String text) {
    return "Hello " + text;
  }

  /**
   * @return A list with all the symbols.
   */
  public List<SymbolInfo> getSymbols() {
    final List<SymbolInfo> list = new ArrayList<SymbolInfo>();

    for (Symbol s : sd.findAll()) {
      SymbolInfo si = new SymbolInfo(s);
      list.add(si);
    }

    return list;
  }

  /**
   * @param symbol A symbol for whose price is to be searched.
   * 
   * @return The quote for the chosen symbol.
   */
  public double getQuote(final String symbol) {
    final Symbol s = sd.findById(symbol);
    return s.getPrice();
  }
}
